// pages/tabbar/tabbar.js
Component({

  properties: {
    tabbrvalue: Number
  },

  /**
   * 页面的初始数据
   */
  data: {
    list: [
      { value: 0, image: '/img/home.png', imaged: '/img/home1.png', ariaLabel: '首页' },
      { value: 1, image: '/img/contact.png', imaged: '/img/contact1.png', ariaLabel: '联系我们' },
      { value: 2, image: '/img/my.png', imaged: '/img/my1.png', ariaLabel: '我的' },
    ],
    hasUnreadTabbarMsg: false
  },

  lifetimes: {
    attached() {
      // 组件初始化时读取红点状态
      this.setData({
        hasUnreadTabbarMsg: wx.getStorageSync('hasUnreadTabbarMsg') || false
      });
    }
  },

  pageLifetimes: {
    show() {
      // 页面显示时同步红点状态
      this.setData({
        hasUnreadTabbarMsg: wx.getStorageSync('hasUnreadTabbarMsg') || false
      });
    }
  },

  methods: {

    onChangeTabbar(e) {
      switch (e.detail.value) {
        case 0:
          if (this.properties.tabbrvalue !== e.detail.value) {
            wx.switchTab({
              url: '/pages/index/index',
            })
          }
          break;
        case 1:
          if (this.properties.tabbrvalue !== e.detail.value) {
            wx.switchTab({
              url: '/pages/members/contact',
            })
          }
          break;
        case 2:
          if (this.properties.tabbrvalue !== e.detail.value) {
            wx.switchTab({
              url: '/pages/members/index',
            })
          }
          break;
        default:
          break;
      }

      this.setData({
        value: e.detail.value,
      });

    },

  },

})